#!conda install -c conda-forge folium=0.5.0 --yes
#import folium
#print('Folium installed and imported!')
import numpy as np # scientific computation
import pandas as pd # primary data structure library
import matplotlib.pyplot as plt #primary plotting stricture
import folium # map generator.
En esta página se muestra el procesamiento de la información correspondiente a los AP de WiFi gratuitos en la ciudad de México. El fin de esta página es crear herramientas visuales que muestren la conectividad en la ciudad, para evaluar y justificar el proyecto de Movilidad Inteligente: conectividad vehicular, a realizar por alumnos de posgrado y pregado del Tecnológico de Monterrey.
A continuación se muestra el proceso de procesamiento y visualización:
df = pd.read_csv('NYC_AP_LOC.csv')
df.head(5)
#df.shape
En este caso, primero se convierte todos los nombres de las columnas en cadenas de caracteres, en caso de que existieran números. Con el fin de homogeneizar la información
df.columns = list(map(str, df.columns))
df.dtypes
df.drop(['Provider', 'OBJECTID','BIN', 'Census Tract', 'BBL', 'DOITT_ID', 'X', 'Y' ], axis = 1, inplace = True)
df.describe(include=['object'])
Podemos ver que hay:
dfBor = df.groupby(['Borough Name']).count().rename(columns={"DIRECCIÓN":"DIR"}).reset_index()
dfBor.head()
dfBorCD = df.groupby(['BoroCD']).count().rename(columns={"DIRECCIÓN":"DIR"}).reset_index()
dfBorCD
El siguiente paso, una vez filtrada nuestra base de datos es hacer visualización geoespacial. Para lograr esto, se recurre al archivo geojson de la ciudad de México, disponible en:
nyc_geo = r'NYC_districts.geojson'
# creating a numpy array of length 6 and has linear spacing from the minium total immigration to the maximum total immigration
threshold_scale = np.linspace(dfBorCD['Location'].min(),
(dfBorCD['Location'].max()-200),
6, dtype=int)
threshold_scale = threshold_scale.tolist() # change the numpy array to a list
threshold_scale[-1] = threshold_scale[-1] + 1 # make sure that the last value of the list is greater than the maximum immigration
mapa_NYC = folium.Map(location=[40.730610 , -73.935242], zoom_start=12, tiles='Mapbox Bright')
mapa_NYC.choropleth(
geo_data=nyc_geo,
data=dfBorCD,
columns=['BoroCD', 'Borough'],
key_on='feature.properties.BoroCD',
#threshold_scale=threshold_scale,
fill_color='BuPu',
fill_opacity=0.7,
line_opacity=0.2,
legend_name='Mapa Coroplexico WiFi Gratuito NYC por Colonias',
reset=True
)
mapa_NYC
from folium import plugins
latitude=40.730610
longitude=-73.935242
# let's start again with a clean copy of the map of San Francisco
map_nyc_num = folium.Map(location = [latitude, longitude], zoom_start = 12)
# instantiate a mark cluster object for the incidents in the dataframe
incidents = plugins.MarkerCluster().add_to(map_nyc_num)
# loop through the dataframe and add each data point to the mark cluster
for lat, lng, label, in zip(df['Latitude'], df['Longitude'], df['SSID']):
folium.Marker(
location=[lat, lng],
icon=None,
popup=label,
).add_to(incidents)
# display map
map_nyc_num